<template>
  <div class="app-container">
    <!--工具栏-->
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <el-form size="small" label-width="100px" v-formkey="{query:toQuery}">
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="业务日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.startTime"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.endTime"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="单据状态">
                <el-select v-model="query.orderStatus" class="edit-input" placeholder="请选择单据状态" style="width: 100%;">
                  <el-option
                    v-for="(item,index) in dict.common_order_status"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="核销状态">
                <el-select v-model="query.cancelStatus" class="edit-input" placeholder="请选择核销状态" style="width: 100%;">
                  <el-option
                    v-for="(item,index) in dict.common_cancel_status"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="单据编号">
                <el-input v-model="query.code" placeholder="输入单号进行搜索"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="来源单据编号">
                <el-input v-model="query.sourceCode" placeholder="输入来源单号进行搜索"/>
              </el-form-item>
            </el-col>

          </el-row>
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="客户名称">
                <zSelect :value.sync="query.customerId" url="api/dropDown/basCustomerList" style="width:  100%;"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="客户单号">
                <el-input v-model="query.customerOrderCode" placeholder="输入客户单号进行搜索"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="是否抽单">
                <el-select v-model="query.isDraw" class="edit-input" placeholder="请选择" style="width: 100%;">
                  <el-option
                    v-for="(item,index) in dict.common_yes_or_no"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="单据类型">
                <el-select v-model="query.type" style="width:  100%"  class="edit-input" placeholder="请选择单据类型" >
                  <el-option
                    v-for="(item,index) in dict.t_sales_begin_type"
                    :key="index"
                    v-if="item.seq>0"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="所属二批">
                <table-select
                  :tableColumns="[{prop:'code',label:'二批编码',width:'100'},{prop:'name',label:'二批名称',width: '280'}]"
                  :value.sync="query.sCustomerIds"
                  placeholder="请选择所属二批"
                  url="/api/dropDown/basCustomerList"
                  :params="{type:3}"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" align="center" style="margin-bottom: 5px;margin-top: 5px">
              <rrOperation :crud="crud"/>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <crudOperation :permission="permission"/>

      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0"
                 :title="crud.status.title" width="70vw">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="100px">
          <el-row :gutter="24">
            <el-col :span="6">
              <el-form-item label="编码">
                <el-input v-model="form.code" disabled style="width: 100%;"/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="业务日期">
                <el-date-picker
                  v-model="form.busDate"
                  type="date"
                  disabled
                  style="width: 100%;"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  placeholder="请选择">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="应收日期">
                <el-date-picker
                  v-model="form.receiveDate"
                  type="date"
                  style="width: 100%;"
                  @change="changeDate"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  placeholder="请选择">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="客户单号">
                <el-input v-model="form.customerOrderCode" style="width: 100%;"/>
              </el-form-item>
            </el-col>
            <el-col :span="6">

              <el-form-item label="客户名称">
                <zSelect :value.sync="form.customerId" :showName="form.customerName" url="api/dropDown/basCustomerList"
                         style="width: 100%;"/>
              </el-form-item>

            </el-col>
            <el-col :span="6">
              <el-form-item label="金额">
                <el-input v-model="form.taxAmount" oninput="value=value.replace(/[^\d^\.]/g,'')"
                          maxlength="12" style="width: 100%;"/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="排序">
                <el-input-number v-model="form.seq" :min="1" label="排序" style="width: 100%;"></el-input-number>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="备注">
                <el-input v-model="form.remark" type="textarea" style="width: 100%;"/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="单据状态">
                <el-select v-model="form.orderStatus" disabled class="edit-input" placeholder="请选择"
                           style="width: 100%;">
                  <el-option
                    v-for="(item,index) in dict.common_order_status"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="单据类型">
                <el-select v-model="form.type" style="width:  100%" class="edit-input" placeholder="请选择单据类型">
                  <el-option
                    v-for="(item,index) in dict.t_sales_begin_type"
                    :key="index"
                    v-if="item.seq>0"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="所属二批">
                <z-select :value.sync="form.sCustomerId"
                          url="/api/dropDown/sCustomerList"
                          @change="changesC"
                          :showName="form.sCustomerName"></z-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>

      <vue-context-menu :contextMenuData="contextMenuData"
                        @tableConfig="tableConfig"
                        @deletedata="deletedata"></vue-context-menu>
      <!-- 表格配置 -->
      <el-dialog title="表格配置"
                 :visible.sync="tableConfigShow"
                 width="60%">
        <j-table-column-config :columns.sync="crud.header" @tabSave="tabSave" @pit="pit"/>
      </el-dialog>

      <!--表格渲染-->
      <el-table ref="table" border
                height="700"
                show-summary
                @cell-dblclick="row=>crud.toEdit(row)"
                v-loading="crud.loading"
                :data="crud.data"
                size="small"
                style="width: 100%;"
                v-if="isShowTable"
                @header-dragend="changeColWidth"
                @contextmenu.native="showMenu"
                :summary-method="sumRow"
                @row-click="crud.selectRow"
                :row-style="crud.rowClass"
                :row-class-name="crud.tableRowClassName"
                @selection-change="crud.selectionChangeHandler">
        <el-table-column :render-header="crud.renderHeader" type="selection" width="60"/>
        <el-table-column :render-header="crud.renderHeader" type="index" width="60" label="序号"/>
        <el-table-column
          v-if="item.visible"
          v-for="(item, index) in crud.header"
          :key="`col_${index}`"
          :prop="item.prop"
          :label="columnLabel(item)"
          :width="item.width + 'px'"
          :data-porp='item.prop'
          @contextmenu.native="showMenu"
          @header-dragend="changeColWidth"
        >

          <!-- 自定义渲染模版 -->
          <template slot-scope="scope">
            <!-- 当列key为 sort 时，渲染一个手柄icon -->
            <template v-if="item.prop =='sort'">
              <div class="handle_move">
                <i :class="scope.row['sort']"/>
              </div>
            </template>
            <template>

              <span :class="{'red':(scope.row[`type`] === 2)}" v-if="item.type == 1" style="margin-left: 0px">
<!--               <span v-if="item.type == 2">-</span>-->
                {{ scope.row[`${item.prop}`] }}
              </span>
              <span v-if="item.type == 2" style="margin-left: 0px">
<!--<span v-if="item.type == 2">-</span>-->
                {{ parseTime(scope.row[`${item.prop}`]) }}
              </span>
              <span :class="{'red':(scope.row[`type`] === 2)}" v-if="item.type == 3" style="margin-left: 0px">
<!--                <span v-if="item.type == 2">-</span>-->

                {{ getDict(`this.dict.label.${item.dictionary}["${scope.row[item.prop]}"]`) }}
              </span>
            </template>
          </template>
        </el-table-column>
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('code')" prop="code" label="编码"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('busDate')" prop="busDate" label="业务日期">-->
        <!--          <template slot-scope="scope">-->
        <!--            <span>{{ parseTime(scope.row.busDate) }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('receiveDate')" prop="receiveDate" label="应收日期">-->
        <!--          <template slot-scope="scope">-->
        <!--            <span>{{ parseTime(scope.row.receiveDate) }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('customerCode')" prop="customerCode" label="客户编码"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('customerName')" prop="customerName" label="客户名称"/>-->
        <!--                <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('customerOrderCode')" prop="customerOrderCode" label="客户单号"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('taxAmount')" prop="taxAmount" label="金额"/>-->
        <!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('noTaxAmount')" prop="noTaxAmount" label="未税金额"/>&ndash;&gt;-->
        <!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('tax')" prop="tax" label="税额"/>&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('isDraw')" prop="isDraw" label="是否抽单">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ dict.label.common_yes_or_no[scope.row.isDraw] }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('drawDate')" prop="drawDate" label="抽单日期">-->
        <!--          <template slot-scope="scope">-->
        <!--            <span>{{ parseTime(scope.row.drawDate) }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('cancelStatus')" prop="cancelStatus" label="核销状态">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ dict.label.common_cancel_status[scope.row.cancelStatus] }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('cancelDate')" prop="cancelDate" label="核销日期">-->
        <!--          <template slot-scope="scope">-->
        <!--            <span>{{ parseTime(scope.row.cancelDate) }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('cancelAmount')" prop="cancelAmount" label="已核销金额"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('unCancelAmount')" prop="unCancelAmount" label="未核销金额"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('seq')" prop="seq" label="排序"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('orderStatus')" prop="orderStatus"-->
        <!--                         label="单据状态">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ dict.label.common_order_status[scope.row.orderStatus] }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('remark')" prop="remark" label="备注"/>-->
        <!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('orderRemark')" prop="orderRemark" label="单据说明"/>&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('createUserName')" prop="createUserName" label="添加人"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('createTime')" prop="createTime" label="添加时间">-->
        <!--          <template slot-scope="scope">-->
        <!--            <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('updateUserName')" prop="updateUserName" label="修改人"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('updateTime')" prop="updateTime" label="修改时间">-->
        <!--          <template slot-scope="scope">-->
        <!--            <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('auditUserName')" prop="auditUserName" label="审核人"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('auditTime')" prop="auditTime" label="审核人时间">-->
        <!--          <template slot-scope="scope">-->
        <!--            <span>{{ parseTime(scope.row.auditTime, '{y}-{m}-{d}') }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('cancelUserName')" prop="cancelUserName" label="核销人" />-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('cancelTime')" prop="cancelTime" label="核销时间">-->
        <!--          <template slot-scope="scope">-->
        <!--            <span>{{ parseTime(scope.row.cancelTime) }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('closeUserName')" prop="closeUserName" label="关闭人"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('closeTime')" prop="closeTime" label="关闭时间">-->
        <!--          <template slot-scope="scope">-->
        <!--            <span>{{ parseTime(scope.row.closeTime, '{y}-{m}-{d}') }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-permission="['admin','salesBegin:edit','salesBegin:del']" label="操作" width="150px"-->
        <!--                         align="center">-->
        <!--          <template slot-scope="scope">-->
        <!--            <udOperation-->
        <!--                :data="scope.row"-->
        <!--                :permission="permission"-->
        <!--            />-->
        <!--          </template>-->
        <!--        </el-table-column>-->
      </el-table>
      <!--分页组件-->
      <pagination/>
    </div>
  </div>
</template>

<script>
import crudSalesBegin from '@/api/erp/salesBegin'
import CRUD, {crud, form, header, presenter} from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import {getAreaTree} from "@/api/erp/basCustomerArea";
import {getDepts} from "@/api/system/dept";
import {getCustomerTypeTree} from "@/api/erp/basCustomerType";
import Treeselect from '@riophae/vue-treeselect'

import {publicListKey} from "@/utils/key";
import {getHeaderProperties} from "@/api/erp/headerProperties";
import {tablemixins} from "@/mixins/tablemixins";
import jTableColumnConfig from "@/components/jTableColumnConfig/jTableColumnConfig";

// crud交由presenter持有
const defaultCrud = CRUD({
  title: '销售期初', name: 'salesBegin', url: 'api/salesBegin', optShow: {
    add: true,
    edit: true,
    del: true,
    download: true,
    leadingIn: true,
    enable: false,
    disable: false,
    pass: true,
    reject: true,
  }, sort: 'id,desc', crudMethod: {...crudSalesBegin},
  //如果携带参数过来则禁止默认查询事件
  queryOnPresenterCreated:!window.location.href.includes('?id'),
  props: {
    tableColumns: [
      'code', //编码
      'name', //名称
      'type', //销售期初类型
      'busDate', //业务日期
      'receiveDate', //应收日期
      'sourceType', //来源类型
      'sourceId', //来源单据id
      'sourceCode', //来源单据号
      'serialNumber', //流水号
      'customerOrderCode', //客户单号
      // 'customerId', //客户id
      // 'customerCode', //客户编码
      'customerName', //客户名称
      'isContact', //是否往来
      // 'customerAreaId', //客户区域id
      // 'customerAreaCode', //客户区域编码
      'customerAreaName', //客户区域名称
      // 'customerTypeId', //客户分类id
      // 'customerTypeCode', //客户分类编码
      'customerTypeName', //客户分类名称
      // 'deptId', //部门id
      // 'deptCode', //部门编码
      'deptName', //部门名称
      // 'userId', //人员id
      // 'userCode', //人员编码
      'userName', //人员名称
      'taxAmount', //含税金额
      'noTaxAmount', //未税金额
      'tax', //税额
      'isDraw', //是否抽单
      'drawDate', //抽单日期
      'cancelStatus', //核销状态
      'cancelDate', //核销日期
      'cancelAmount', //已核销金额
      'unCancelAmount', //未核销金额
      'seq', //排序
      'orderStatus', //orderStatus
      'remark', //备注
      'orderRemark', //单据说明
    ]
  }
})
const defaultForm = {
  id: null,
  code: null,
  name: null,
  type: null,
  busDate: null,
  receiveDate: null,
  sourceType: null,
  sourceId: null,
  sourceCode: null,
  serialNumber: null,
  customerOrderCode: null,
  customerId: null,
  customerCode: null,
  customerName: null,
  isContact: null,
  customerAreaId: null,
  customerAreaCode: null,
  customerAreaName: null,
  customerTypeId: null,
  customerTypeCode: null,
  customerTypeName: null,
  deptId: null,
  deptCode: null,
  deptName: null,
  userId: null,
  userCode: null,
  userName: null,
  taxAmount: null,
  noTaxAmount: null,
  tax: null,
  isDraw: null,
  drawDate: null,
  cancelStatus: null,
  cancelDate: null,
  cancelAmount: null,
  unCancelAmount: null,
  seq: null,
  orderStatus: null,
  remark: null,
  orderRemark: null,
  createUserId: null,
  createUserCode: null,
  createUserName: null,
  createTime: null,
  updateUserId: null,
  updateUserCode: null,
  updateUserName: null,
  updateTime: null,
  auditUserId: null,
  auditUserCode: null,
  auditUserName: null,
  auditTime: null,
  closeUserId: null,
  closeUserCode: null,
  closeUserName: null,
  closeTime: null,
  sCustomerId: null,
  sCustomerName: null,
  sCustomerCode: null
}
export default {
  name: 'SalesBegin',
  components: {pagination, crudOperation, rrOperation, udOperation, Treeselect, jTableColumnConfig},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(), publicListKey, tablemixins],
  dicts: ['common_order_status', 'common_cancel_status', 'common_yes_or_no','t_sales_begin_type'],
  data() {
    return {

      permission: {
        add: ['admin', 'salesBegin:add'],
        edit: ['admin', 'salesBegin:edit'],
        del: ['admin', 'salesBegin:del'],
        import: ['admin', 'salesBegin:import'],
        export: ['admin', 'salesBegin:export'],
        copy: ['admin', 'salesBegin:copy'],
        upload: ['admin', 'salesBegin:upload'],
        download: ['admin', 'salesBegin:download'],
        pass: ['admin', 'salesBegin:pass'],
        reject: ['admin', 'salesBegin:reject'],
        closed: ['admin', 'salesBegin:closed'],
        invalid: ['admin', 'salesBegin:invalid'],
        stop: ['admin', 'salesBegin:stop'],
        recover: ['admin', 'salesBegin:recover'],
      },
      rules: {},
      red:['taxAmount','cancelAmount','unCancelAmount'],
      typeList: [],
      areaList: [],
      depts: [],
    }
  },
  activated() {
    if(this.$route.query.id){
      this.query.id=this.$route.query.id
      this.crud.refresh()
    }else {
      this.$route.query.id = null
    }
  },
  created() {
    this.getTypeList()
    this.getAreaList()
    this.getDepts()
  },
  watch: {
    'crud.data':{
      handler(n,o){
        if (!this.crud.data[0].isUpdate){
          this.crud.data[0].isUpdate=true
          const dataList = this.crud.data.filter(item=>item.type === 2)
          for (let i of this.red){
            for (let data of dataList ){
              if (data[i])
                data[i] = Number(data[i]) * -1
            }
          }
        }

      },
      deep:true
    },
  },
  updated() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  methods: {
    changesC(e){
      this.form.scustomerId=e.id
      this.form.scustomerCode=e.code
      this.form.scustomerName=e.name
      this.form.sCustomerCode=e.code
      this.form.sCustomerName=e.name
    },
    getValue(e) {
      this.query.startTime = this.query.dataExtent[0]
      this.query.endTime = this.query.dataExtent[1]
    },
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
    changeDate(e) {
      this.form.busDate = e
    },
    getAreaList() {
      getAreaTree().then(res => {
        this.areaList = res
      })
    },
    sumRow({ columns, data }){
      console.log(this.crud)
      const sums = []
      //所有有值的字段
      if (this.crud.summary instanceof Array)return;

      const sumFiled = Object.keys(this.crud.summary).filter(item=>this.crud.summary[item]!== null)

      for (let i in  columns) {
        if (sumFiled.includes(columns[i].property)) {
          let selectSum = 0
          this.$refs.table.selection.forEach(item => {
            selectSum += item[columns[i].property]
          })
          sums[i] = <p>{selectSum}
            <hr/>
            {this.crud.summary[columns[i].property] || 0}</p>
        }
        sums[0] = <p>选中
          <hr/>
          合计</p>
      }
      return sums
    },

    // 获取弹窗内部门数据
    getDepts() {
      getDepts({status: 1}).then(res => {
        this.depts = res
      })
    },
    getTypeList() {
      getCustomerTypeTree({page: 0, size: 999}).then(res => {
        this.typeList = res
      })
    },
    normalizer(node) {
      //去掉children=[]的children属性
      if (node.children == null || node.children.length == 0) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children
      }
    }
  }
}
</script>

<style scoped>
.red {
  color: red;
}

.table-img {
  display: inline-block;
  text-align: center;
  background: #ccc;
  color: #fff;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  vertical-align: middle;
  width: 32px;
  height: 32px;
  line-height: 32px;
}
</style>
